mui.init({
	beforeback: function() {
		//获得列表界面的webview
		var parentObj = plus.webview.currentWebview().opener();
		//触发列表界面的自定义事件(dataList),从而进行数据刷新
		mui.fire(parentObj, 'dataList');
		//返回true,继续页面关闭逻辑
		return true;
	}
});

var kefuDetails;
mui.plusReady(function() {
	var vself = plus.webview.currentWebview();
	kefuDetails = new Vue({
		el: '#list_box',
		data: {
			details: '',
			status: vself.status,
		},
		mounted() {
			this.getKefuDetails();
		},
		methods: {
			getKefuDetails: function() {
				showWatting();
				var api_host = plus.storage.getItem('HOST_URL');
				var self = this;
				mui.ajax({
					url: api_host + '/api/cusservice/cusservice/cusone',
					dataType: 'json',
					data: {
						'id': vself.kid
					},
					headers: {
						'User-Token': plus.storage.getItem('UserToken')
					},
					type: 'get',
					success: function(msg) {
						self.details = msg.data;
					},
					error: function() {
						console.log('获取客服详情出错了');
					},
					complete: function() {
						plus.nativeUI.closeWaiting();
					}
				})
			},
			copy_weixin: function(event) {
				var th = event.currentTarget;
				var clipboard = new ClipboardJS(th);
				clipboard.on('success', function(th) {
					mui.toast('微信号已复制!');
				});

				clipboard.on('error', function(e) {
					console.log(e);
				});
			},
			chatQQ: function(qq) {
				window.location.href = "mqqwpa://im/chat?chat_type=wpa&uin=" + qq +
					"&version=1&src_type=web&web_src=oicqzone.com";
			},
			callPhone: function(mobile) {
				window.location.href = 'tel:' + mobile;
			},
			mailTo: function(email) {
				window.location.href = 'mailto:' + email;
			},
			showDialog: function() {
				var self = this;
				plus.nativeUI.confirm('确定选择【'+self.details.name+'】为您的专属客服吗？', function (e) {
					if(e.index == 0){
						var api_host = plus.storage.getItem('HOST_URL');
						mui.ajax({
							url: api_host + '/api/cusservice/cusservice/addMemberCustomer',
							dataType: 'json',
							data: {
								'custom_id': self.details.id,
								'name': self.details.name
							},
							headers: {
								'User-Token': plus.storage.getItem('UserToken')
							},
							type: 'post',
							async: true,
							timeout: 1000,
							success: function(data) {
								mui.toast(data.msg, {duration: '1000',type: 'div'});
								if(data.code == 1){
									setTimeout(function () {
										mui.back();
									},1500)
								}
							},
							error: function(xhr, type, errorThrown) {
								console.log('系统错误');
							}
						});
					}else{
						mui.toast('已取消', {duration: '200',type: 'div'});
					}
				}, {
					buttons:['确定','取消']
				});
			}
		}
	})
})
